package com.example.swd1.gudong.view;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.example.swd1.gudong.R;


//==================================================================================================================
//   Author :  Shile Wu
//   Date  :  16-8-29
//   Role :   the dialog pop when press start running
//   Reference documents : None
//==================================================================================================================
public class FinishSportDialog extends Dialog implements View.OnClickListener {

    private TextView finishText,continueText;

    private int height,width;
    private Context context;
    private OnclickListener listener;



    public FinishSportDialog(Context context, int height, int width, int style) {
        super(context,style);
        this.context = context;
        this.height = height;
        this.width = width;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_finish_sport);
        finishText = (TextView) findViewById(R.id.finish_text);
        continueText = (TextView) findViewById(R.id.continue_text);

        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        //set width,height by density and gravity
        float density = getDensity(context);
        params.width = (int) (width*density);
        params.height = (int) (height*density);
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);

        finishText.setOnClickListener(this);
        continueText.setOnClickListener(this);

    }

    private float getDensity(Context context) {
        Resources resources = context.getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
        return dm.density;
    }

    public void setOnClickListener(OnclickListener listener){
        this.listener = listener;
    }

    @Override
    public void onClick(View v) {
        listener.onClick(v.getId());
    }

    public interface OnclickListener{
        void onClick(int id);
    }
}
